package kotan.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;

import kotan.model.KindModel;
import kotan.view.table.EntityTableView;

/**
 * Application main frame extends JFrame.
 * @author shuji.w6e
 * @since 1.0
 */
public class AppFrame extends JFrame {
    private static final long serialVersionUID = 1L;

    private AppPanel appPanel;

    private StatusBar statusBar;

    public AppFrame() {
        initComponents();
    }

    private void initComponents() {
        AppMenu appMenu = new AppMenu();
        this.setJMenuBar(appMenu.getMenuBar());
        NavigationPanel naviPanel = new NavigationPanel();
        appPanel = new AppPanel();
        statusBar = new StatusBar();
        // Layout
        this.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        this.add(naviPanel, gbc);
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        this.add(appPanel, gbc);
        gbc.gridy = 2;
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        this.add(statusBar, gbc);
    }

    public void activateProgressBar() {
        statusBar.setActive(true);
    }

    public void disactivateProgressBar() {
        statusBar.setActive(false);
    }

    public void resetProgress(int size) {
        statusBar.progressBar.setValue(0);
        statusBar.progressBar.setMinimum(0);
        statusBar.progressBar.setMaximum(size);
    }

    public void setProgress(int value) {
        statusBar.progressBar.setValue(value);
    }

    public void addEntityViewer(String kind) {
        appPanel.addTab(kind, new EntityTableView());
    }

    public void setKindModel(KindModel model) {
        appPanel.getEntityViewerPanel(model.getName()).setKind(model);
    }

}
